@extends('layouts.base') @section('content') @parent
<div id="wrapper">
    <div class="main-content container">
        <div class="row small-spacing">
            <div class="col-lg-9 col-xs-9">
                <div class="box-content">
                    <h4 class="box-title text-warning">
                        模版管理&nbsp; &nbsp;
                        <button type="button" class="btn btn-default waves-effect waves-light" data-toggle="modal"
                                data-target="#addTask">Add
                        </button>
                    </h4>
                    <!-- /.box-title -->
                    <div class="task-lists">
                        @foreach($templates as $template)
                            <div class="row task-item">
                                <div class="col-md-9 col-xs-9 title">
                                    <button class="btn btn-success btn-xs waves-effect waves-light">{{$template->sites->name}}</button>
                                    <span>{{$template->template}}</span>
                                </div>

                                <div class="col-md-3 col-xs-3 text-right">
                                    <button type="button" class="btn btn-info btn-xs waves-effect waves-light"
                                            data-toggle="modal" data-target="#editstartend"
                                            data-id="{{$template->id}}" data-cat="{{$template->sites_id}}"
                                            data-type="{{$template->is_use}}" data-value="{{$template->template}}"
                                            data-url="{{route('template.update',$template->id)}}">
                                        <i class="fa fa-pencil" aria-hidden="true"></i> 编辑
                                    </button>
                                    &nbsp;&nbsp;
                                    <form action="{{ route('template.destroy', $template->id) }}" method="post"
                                          style="display: inline-block;">
                                        {{ csrf_field() }} {{ method_field('DELETE') }}
                                        <button type="submit" data-delete="{{$template->id}}"
                                                class="btn btn-orange btn-xs waves-effect waves-light">
                                            <i class="fa fa-trash" aria-hidden="true"></i> 删除
                                        </button>
                                    </form>
                                </div>
                            </div>
                        @endforeach
                    </div>

                    <!-- /.task-lists -->
                    <div class="text-center">
                        {{$templates->links()}}
                    </div>
                </div>
                <!-- /.box-content -->
            </div>

            <div class="col-md-3">
                <a href=""
                   class="btn btn-danger btn-mail-main btn-block margin-bottom-20 waves-effect waves-light">站点查看</a>
                <div class="box box-solid">
                    <div class="box-body">
                        <ul class="nav nav-pills nav-stacked">
                            @foreach($sites as $site)
                                <li>
                                    <a href="{{route('template.index',['site'=>$site->id])}}">
                                        <i class="fa fa-inbox"></i> {{$site->name}}
                                        <span class="label-right bg-info pull-right">{{$site->templates()->count()}}</span>
                                    </a>
                                </li>
                            @endforeach
                        </ul>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /. box -->
            </div>
            <!-- /.col-lg-4 col-xs-12 -->
        </div>
        <!-- /.row small-spacing -->
    </div>
    <!-- /.main-content -->
</div>
<!--/#wrapper -->
<div class="modal fade" id="addTask" tabindex="-1" role="dialog" aria-labelledby="addTaskLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="POST" action="{{route('template.store')}}">
                {{ csrf_field() }}
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="addTaskLabel">Add模版</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>是否使用该模版</label>
                                <ul class="list-inline">
                                    <li>
                                        <div class="radio info">
                                            <input type="radio" name="is_use" id="start" value="1" class="form-control">
                                            <label for="start">使用</label></div>
                                    </li>
                                    <li>
                                        <div class="radio info">
                                            <input type="radio" name="is_use" id="end" value="0" checked
                                                   class="form-control">
                                            <label for="end">不使用</label></div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="slug">所属站点</label>
                                <select class="form-control" name="sites_id" id="cat" required>
                                    @foreach($sites as $site)
                                        <option value="{{$site->id}}">{{$site->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <h5><b>模版内容</b></h5>
                            <h6>关键词：#tips#、#logo#、#word#单词、#soundmark#音标、#interpret#翻译、#interpretmore#更多翻译、#sentences#例句</h6>
                            <textarea id="textarea" name="template" class="form-control" cols="60" rows="6"
                                      placeholder="输入模版内容。。。"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default waves-effect waves-light" data-dismiss="modal">取消
                    </button>
                    <button type="submit" class="btn btn-primary waves-effect waves-light">添加</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="editstartend" tabindex="-1" role="dialog" aria-labelledby="editstartendLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form id="editForm" method="POST" action="">
                {{ csrf_field() }}
                {{--{{ method_field('PUT') }}--}}
                <input type="hidden" name="_method" value="put">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="addTaskLabel">Add模版</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label>是否使用该模版</label>
                                <ul class="list-inline">
                                    <li>
                                        <div class="radio info">
                                            <input type="radio" name="is_use" id="estart" value="1"
                                                   class="form-control">
                                            <label for="estart">使用</label></div>
                                    </li>
                                    <li>
                                        <div class="radio info">
                                            <input type="radio" name="is_use" id="eend" value="0" class="form-control">
                                            <label for="eend">不使用</label></div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="slug">所属站点</label>
                                <select class="form-control" name="sites_id" id="catselect" required>
                                    @foreach($sites as $site)
                                        <option value="{{$site->id}}">{{$site->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="for-group">
                                <h5><b>模版内容</b></h5>
                                <h6>关键词：#tips#、#logo#、#word#单词、#soundmark#音标、#interpret#翻译、#interpretmore#更多翻译、#sentences#例句</h6>
                            <textarea id="textarea" name="template" class="form-control" cols="60" rows="6"
                                      placeholder="输入模版内容。。。"></textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default waves-effect waves-light" data-dismiss="modal">取消
                    </button>
                    <button type="submit" class="btn btn-primary waves-effect waves-light">更改</button>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection @section('scriptsafter') @parent
<script>
    $('#editstartend').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget)
        var id = button.data('id')
        var ttype = button.data('type')
        var catid = button.data('cat')
        var value = button.data('value')
        var url = button.data('url')
        var modal = $(this)
        $("#editForm").attr("action", url);
        modal.find('input[name=is_use]').each(function (i, v) {
            if (ttype == $(this).val()) {
                $(this).prop('checked', true);
            }
        })
        modal.find('select[name=sites_id]').val(catid);
        modal.find('.modal-title').text('修改id为' + id + '的内容')
        modal.find('.modal-body textarea').val(value)
    })
</script>
@endsection